package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxxx.server.pojo.AdminRole;
import com.xxxx.server.mapper.AdminRoleMapper;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IAdminRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lsh
 * @since 2021-03-07
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements IAdminRoleService {

    @Autowired
    private AdminRoleMapper adminRoleMapper;

    /**
     * 更新操作员角色
     * 先把所有角色删除，再添加
     * 涉及到两个操作要添加事务注解
     */
    @Transactional
    @Override
    public RespBean updateAdminRole(Integer adminId, Integer[] rids) {
        adminRoleMapper.delete(new QueryWrapper<AdminRole>().eq("adminId",adminId));
        Integer result = adminRoleMapper.updateAdminRole(adminId, rids);
        if(result==rids.length){
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }
}